//
//  HomeViewController.m
//  iWeddingDirectory
//
//  Created by Tung Ngo on 5/18/12.
//  Copyright (c) 2012 Home. All rights reserved.
//

#import "HomeViewController.h"
#import <QuartzCore/QuartzCore.h>

@implementation HomeViewController
@synthesize theTableView;
@synthesize imageViewSlideBanner;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Home" image:[UIImage imageNamed:@"home.png"] tag:0];
        self.tabBarItem = item;
        [item release];
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
    UIImageView *topbarLogo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iWeddingLogoFull.png"]];
    topbarLogo.frame = CGRectMake(105, 0, 110, 40);
    [self.navigationController.navigationBar addSubview:topbarLogo];
    [topbarLogo release];
    
    theTableView.backgroundColor = [UIColor clearColor];
    imageViewSlideBanner.layer.borderWidth = 0;
    imageViewSlideBanner.layer.cornerRadius = 10;
    imageViewSlideBanner.clipsToBounds = YES;
    imageViewSlideBanner.animationDuration = 7.;
    imageViewSlideBanner.animationRepeatCount = -1;
    imageViewSlideBanner.animationImages = [NSArray arrayWithObjects:
                                            [UIImage imageNamed:@"Picture001.jpg"], 
                                            [UIImage imageNamed:@"Picture002.jpg"], 
                                            [UIImage imageNamed:@"Picture003.jpg"], 
                                            [UIImage imageNamed:@"Picture004.jpg"], 
                                            [UIImage imageNamed:@"Picture005.jpg"], 
                                            nil];
    [imageViewSlideBanner startAnimating];
}

- (void)viewDidUnload
{
    [self setTheTableView:nil];
    [self setImageViewSlideBanner:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [theTableView release];
    [imageViewSlideBanner release];
    [super dealloc];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    // Configure the cell...
    int row = indexPath.row;
    if (row == 0) {
        cell.textLabel.text = @"Search";
    }
    else if (row == 1) {
        cell.textLabel.text = @"Inquire To All";
    }
    else if (row == 2) {
        cell.textLabel.text = @"Login/Register";
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    int row = indexPath.row;
    if (row == 0) {
        self.tabBarController.selectedIndex = 2;
    }
    else if (row == 1) {
        self.tabBarController.selectedIndex = 1;
    }
    else if (row == 2) {
        self.tabBarController.selectedIndex = 6;
    }
}

@end
